package com.atguigu.mvc.interceptors;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 陆小根
 * date: 2022/05/03
 * Description:
 * 去实现HandlerInterceptor
 * 继承 HandlerInterceptorAdaptor(过时)
 */
@Component
public class FirstInterceptor implements HandlerInterceptor {
  // true--->放行  false--->拦截
  @Override // 控制器执行之前
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    System.out.println("FirstInterceptor-->preHandle");
    return true;
  }

  @Override // 控制器执行之后
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    System.out.println("FirstInterceptor-->postHandle");
  }

  @Override // 视图渲染完成之后
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    System.out.println("FirstInterceptor-->afterCompletion");
  }
}
